package com.government.company.service.impl;

import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.government.app.vo.KeywordSearchDetailsVO;
import com.government.area.domain.Area;
import com.government.area.domain.ParkArea;
import com.government.area.mapper.AreaMapper;
import com.government.area.mapper.ParkAreaMapper;
import com.government.common.core.domain.entity.SysUser;
import com.government.common.exception.ServiceException;
import com.government.common.utils.DateUtils;
import com.government.common.utils.StringUtils;
import com.government.company.bo.CompanyExcel;
import com.government.company.bo.QccCompanyExcel;
import com.government.company.domain.*;
import com.government.company.mapper.CompanyAccsMapper;
import com.government.company.mapper.CompanyPatentMapper;
import com.government.company.mapper.IndustryMapper;
import com.government.item.domain.ExcelDetail;
import com.government.item.mapper.ExcelDetailMapper;
import com.government.system.mapper.SysUserMapper;
import com.government.tag.domain.Tag;
import com.government.tag.mapper.TagMapper;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.government.company.mapper.CompanyMapper;
import com.government.company.service.ICompanyService;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import static com.government.common.utils.SecurityUtils.getLoginUser;

/**
 * 公司Service业务层处理
 *
 * @author system
 * @date 2023-09-15
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CompanyServiceImpl implements ICompanyService {
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private AreaMapper areaMapper;
    @Autowired
    private ParkAreaMapper parkAreaMapper;
    @Autowired
    private IndustryMapper industryMapper;
    @Autowired
    private TagMapper tagMapper;
    @Autowired
    private CompanyPatentMapper companyPatentMapper;
    @Autowired
    private CompanyAccsMapper companyAccsMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    @Resource(name = "serviceThreadPool")
    private ExecutorService executorService;

    @Autowired
    private ExcelDetailMapper excelDetailMapper;

    private static final String appkey = "a78797d974e64168a59e815f1dccdac2";
    private static final String secretKey = "CE1EE277D1CEFD799C3C59C9AFB1D5F1";

    /**
     * 查询公司
     *
     * @param id 公司主键
     * @return 公司
     */
    @Override
    public Company selectCompanyById(Long id) {
        Company company = companyMapper.selectById(id);
        if (StrUtil.isNotBlank(company.getAreaId())) {
            String[] areaIdStr = company.getAreaId().split(",");
            company.setAreaIds(Arrays.asList(areaIdStr));
        }
        if (StrUtil.isNotBlank(company.getParkAreaId())) {
            String[] parkAreaIdStr = company.getParkAreaId().split(",");
            company.setParkAreaIds(Arrays.asList(parkAreaIdStr));
        }
        if (StrUtil.isNotBlank(company.getIndustryId())) {
            String[] industryIdStr = company.getIndustryId().split(",");
            company.setIndustryIds(Arrays.asList(industryIdStr));
        }
        return company;
    }

    /**
     * 查询公司列表
     *
     * @param company 公司
     * @return 公司
     */
    @Override
    public List<Company> selectCompanyList(Company company) {

        List<Company> companyList = companyMapper.selectCompanyList(company);

//        List<Area> areaList = areaMapper.selectList(Wrappers.<Area>lambdaQuery());
//        Map<Long, String> areaMap = areaList.stream().collect(Collectors.toMap(Area::getId, Area::getName));

        List<ParkArea> parkAreaList = parkAreaMapper.selectList(Wrappers.<ParkArea>lambdaQuery());
        Map<Long, String> parkAreaMap = parkAreaList.stream().collect(Collectors.toMap(ParkArea::getId, ParkArea::getName));

        Set<Long> userIds = new HashSet<>();
        for (Company item : companyList) {
            if (StrUtil.isNotBlank(item.getUpdateBy())) {
                userIds.add(Long.parseLong(item.getUpdateBy()));
            }
        }
        Map<Long, String> userMap = new HashMap<>();
        if (CollUtil.isNotEmpty(userIds)) {
            List<SysUser> userList = sysUserMapper.selectList(Wrappers.<SysUser>lambdaQuery().in(SysUser::getUserId, userIds));
            if (CollUtil.isNotEmpty(userList)) {
                userMap = userList.stream().collect(Collectors.toMap(SysUser::getUserId, SysUser::getUserName));
            }
        }

        for (Company item : companyList) {
//            if (StrUtil.isNotBlank(item.getAreaId())) {
//                List<String> areaIdList = Arrays.asList(item.getAreaId().split(","));
//                List<String> areaNameList = new ArrayList<>();
//                for (String areaId : areaIdList) {
//                    areaNameList.add(areaMap.get(Long.parseLong(areaId)));
//                }
//                item.setAreaName(String.join("-", areaNameList));
//            }
            if (StrUtil.isNotBlank(item.getParkAreaId())) {
                List<String> parkAreaIdList = Arrays.asList(item.getParkAreaId().split(","));
                List<String> parkAreaNameList = new ArrayList<>();
                for (String parkAreaId : parkAreaIdList) {
                    if (!"null".equals(parkAreaId)) {
                        parkAreaNameList.add(parkAreaMap.get(Long.parseLong(parkAreaId)));
                    }
                }
                item.setParkAreaName(String.join("-", parkAreaNameList));
            }
            if (StrUtil.isNotBlank(item.getUpdateBy())) {
                item.setUpdateName(userMap.get(Long.parseLong(item.getUpdateBy())));
            }
        }
        return companyList;
    }

    /**
     * 新增公司
     *
     * @param company 公司
     * @return 结果
     */
    @Override
    public int insertCompany(Company company) {
        List<Area> areaList = areaMapper.selectList(Wrappers.<Area>lambdaQuery());
        Map<Long, String> areaMap = areaList.stream().collect(Collectors.toMap(Area::getId, Area::getName));

        List<ParkArea> parkAreaList = parkAreaMapper.selectList(Wrappers.<ParkArea>lambdaQuery());
        Map<Long, String> parkAreaMap = parkAreaList.stream().collect(Collectors.toMap(ParkArea::getId, ParkArea::getName));

        List<Industry> industryList = industryMapper.selectList(Wrappers.<Industry>lambdaQuery().eq(Industry::getIsDeleted, "0"));
        Map<Long, String> industryMap = industryList.stream().collect(Collectors.toMap(Industry::getId, Industry::getName));

        // 地区
        if (CollUtil.isNotEmpty(company.getAreaIds())) {

            if (company.getAreaIds().size() > 0) {
                Long provinceId = Long.parseLong(company.getAreaIds().get(0));
                company.setProvince(provinceId);
                company.setProvinceName(areaMap.get(provinceId));
            }
            if (company.getAreaIds().size() > 1) {
                Long cityId = Long.parseLong(company.getAreaIds().get(1));
                company.setCity(cityId);
                company.setCityName(areaMap.get(cityId));
            }
            if (company.getAreaIds().size() > 2) {
                Long districtId = Long.parseLong(company.getAreaIds().get(2));
                company.setDistrict(districtId);
                company.setDistrictName(areaMap.get(districtId));
            }
            company.setAreaId(String.join(",", company.getAreaIds()));
        }
        // 园区
        if (CollUtil.isNotEmpty(company.getParkAreaIds())) {
            if (company.getParkAreaIds().size() > 0) {
                Long park1 = Long.parseLong(company.getParkAreaIds().get(0));
                company.setPark1(park1);
                company.setLastPark(park1);
                company.setParkName1(parkAreaMap.get(park1));
                company.setLastParkName(parkAreaMap.get(park1));
            }
            if (company.getParkAreaIds().size() > 1) {
                Long park2 = Long.parseLong(company.getParkAreaIds().get(1));
                company.setPark2(park2);
                company.setLastPark(park2);
                company.setParkName2(parkAreaMap.get(park2));
                company.setLastParkName(parkAreaMap.get(park2));
            }
            if (company.getParkAreaIds().size() > 2) {
                Long park3 = Long.parseLong(company.getParkAreaIds().get(2));
                company.setPark3(park3);
                company.setLastPark(park3);
                company.setParkName3(parkAreaMap.get(park3));
                company.setLastParkName(parkAreaMap.get(park3));
            }
            if (company.getParkAreaIds().size() > 3) {
                Long park4 = Long.parseLong(company.getParkAreaIds().get(3));
                company.setPark4(park4);
                company.setLastPark(park4);
                company.setParkName4(parkAreaMap.get(park4));
                company.setLastParkName(parkAreaMap.get(park4));
            }
            if (company.getParkAreaIds().size() > 4) {
                Long park5 = Long.parseLong(company.getParkAreaIds().get(4));
                company.setPark5(park5);
                company.setLastPark(park5);
                company.setParkName5(parkAreaMap.get(park5));
                company.setLastParkName(parkAreaMap.get(park5));
            }
            if (company.getParkAreaIds().size() > 5) {
                Long park6 = Long.parseLong(company.getParkAreaIds().get(5));
                company.setPark6(park6);
                company.setLastPark(park6);
                company.setParkName6(parkAreaMap.get(park6));
                company.setLastParkName(parkAreaMap.get(park6));
            }
            company.setParkAreaId(String.join(",", company.getParkAreaIds()));
        }

        // 行业
        if (CollUtil.isNotEmpty(company.getIndustryIds())) {

            if (company.getIndustryIds().size() > 0) {
                Long industry1 = Long.parseLong(company.getIndustryIds().get(0));
                company.setIndustry1(industry1);
                company.setIndustryName1(industryMap.get(industry1));
            }
            if (company.getIndustryIds().size() > 1) {
                Long industry2 = Long.parseLong(company.getIndustryIds().get(1));
                company.setIndustry2(industry2);
                company.setIndustryName2(industryMap.get(industry2));
            }
            if (company.getIndustryIds().size() > 2) {
                Long industry3 = Long.parseLong(company.getIndustryIds().get(2));
                company.setIndustry3(industry3);
                company.setIndustryName3(industryMap.get(industry3));
            }
            if (company.getIndustryIds().size() > 3) {
                Long industry4 = Long.parseLong(company.getIndustryIds().get(3));
                company.setIndustry4(industry4);
                company.setIndustryName4(industryMap.get(industry4));
            }
            company.setIndustryId(String.join(",", company.getIndustryIds()));
        }
        // 性质处理
        companyNatureHandler(company);
        company.setCreateTime(DateUtils.getNowDate());
        companyMapper.insert(company);

        // 反向关联上立项数据中的企业id
        int count = excelDetailMapper.selectCount(Wrappers.<ExcelDetail>lambdaQuery().eq(ExcelDetail::getIncorporation, company.getName()));
        if (count > 0) {
            excelDetailMapper.updateExcelDetailByCompany(company.getName(), company.getId());
        }
        return 1;
    }

    /**
     * 修改公司
     *
     * @param company 公司
     * @return 结果
     */
    @Override
    public int updateCompany(Company company) {

        SysUser user = getLoginUser().getUser();

        List<Area> areaList = areaMapper.selectList(Wrappers.<Area>lambdaQuery());
        Map<Long, String> areaMap = areaList.stream().collect(Collectors.toMap(Area::getId, Area::getName));

        List<ParkArea> parkAreaList = parkAreaMapper.selectList(Wrappers.<ParkArea>lambdaQuery());
        Map<Long, String> parkAreaMap = parkAreaList.stream().collect(Collectors.toMap(ParkArea::getId, ParkArea::getName));

        List<Industry> industryList = industryMapper.selectList(Wrappers.<Industry>lambdaQuery().eq(Industry::getIsDeleted, "0"));
        Map<Long, String> industryMap = industryList.stream().collect(Collectors.toMap(Industry::getId, Industry::getName));
        // 地区
        if (CollUtil.isNotEmpty(company.getAreaIds())) {
            company.setProvince(null);
            company.setProvinceName("");
            company.setCity(null);
            company.setCityName("");
            company.setDistrict(null);
            company.setDistrictName("");
            if (company.getAreaIds().size() > 0) {
                Long provinceId = Long.parseLong(company.getAreaIds().get(0));
                company.setProvince(provinceId);
                company.setProvinceName(areaMap.get(provinceId));
            }
            if (company.getAreaIds().size() > 1) {
                Long cityId = Long.parseLong(company.getAreaIds().get(1));
                company.setCity(cityId);
                company.setCityName(areaMap.get(cityId));
            }
            if (company.getAreaIds().size() > 2) {
                Long districtId = Long.parseLong(company.getAreaIds().get(2));
                company.setDistrict(districtId);
                company.setDistrictName(areaMap.get(districtId));
            }
            company.setAreaId(String.join(",", company.getAreaIds()));
        }
        // 园区
        if (CollUtil.isNotEmpty(company.getParkAreaIds())) {
            company.setPark1(null);
            company.setParkName1("");
            company.setPark2(null);
            company.setParkName2("");
            company.setPark3(null);
            company.setParkName3("");
            company.setPark4(null);
            company.setParkName4("");
            company.setPark5(null);
            company.setParkName5("");
            company.setPark6(null);
            company.setParkName6("");
            company.setLastPark(null);
            company.setLastParkName("");
            if (company.getParkAreaIds().size() > 0) {
                Long park1 = Long.parseLong(company.getParkAreaIds().get(0));
                company.setPark1(park1);
                company.setLastPark(park1);
                company.setParkName1(parkAreaMap.get(park1));
                company.setLastParkName(parkAreaMap.get(park1));
            }
            if (company.getParkAreaIds().size() > 1) {
                Long park2 = Long.parseLong(company.getParkAreaIds().get(1));
                company.setPark2(park2);
                company.setLastPark(park2);
                company.setParkName2(parkAreaMap.get(park2));
                company.setLastParkName(parkAreaMap.get(park2));
            }
            if (company.getParkAreaIds().size() > 2) {
                Long park3 = Long.parseLong(company.getParkAreaIds().get(2));
                company.setPark3(park3);
                company.setLastPark(park3);
                company.setParkName3(parkAreaMap.get(park3));
                company.setLastParkName(parkAreaMap.get(park3));
            }
            if (company.getParkAreaIds().size() > 3) {
                Long park4 = Long.parseLong(company.getParkAreaIds().get(3));
                company.setPark4(park4);
                company.setLastPark(park4);
                company.setParkName4(parkAreaMap.get(park4));
                company.setLastParkName(parkAreaMap.get(park4));
            }
            if (company.getParkAreaIds().size() > 4) {
                Long park5 = Long.parseLong(company.getParkAreaIds().get(4));
                company.setPark5(park5);
                company.setLastPark(park5);
                company.setParkName5(parkAreaMap.get(park5));
                company.setLastParkName(parkAreaMap.get(park5));
            }
            if (company.getParkAreaIds().size() > 5) {
                Long park6 = Long.parseLong(company.getParkAreaIds().get(5));
                company.setPark6(park6);
                company.setLastPark(park6);
                company.setParkName6(parkAreaMap.get(park6));
                company.setLastParkName(parkAreaMap.get(park6));
            }
            company.setParkAreaId(String.join(",", company.getParkAreaIds()));
        }

        // 行业
        if (CollUtil.isNotEmpty(company.getIndustryIds())) {
            company.setIndustry1(null);
            company.setIndustryName1("");
            company.setIndustry2(null);
            company.setIndustryName2("");
            company.setIndustry2(null);
            company.setIndustryName2("");
            company.setIndustry2(null);
            company.setIndustryName2("");
            if (company.getIndustryIds().size() > 0) {
                Long industry1 = Long.parseLong(company.getIndustryIds().get(0));
                company.setIndustry1(industry1);
                company.setIndustryName1(industryMap.get(industry1));
            }
            if (company.getIndustryIds().size() > 1) {
                Long industry2 = Long.parseLong(company.getIndustryIds().get(1));
                company.setIndustry2(industry2);
                company.setIndustryName2(industryMap.get(industry2));
            }
            if (company.getIndustryIds().size() > 2) {
                Long industry3 = Long.parseLong(company.getIndustryIds().get(2));
                company.setIndustry3(industry3);
                company.setIndustryName3(industryMap.get(industry3));
            }
            if (company.getIndustryIds().size() > 3) {
                Long industry4 = Long.parseLong(company.getIndustryIds().get(3));
                company.setIndustry4(industry4);
                company.setIndustryName4(industryMap.get(industry4));
            }
            company.setIndustryId(String.join(",", company.getIndustryIds()));
        }
        // 性质处理
        companyNatureHandler(company);
        company.setUpdateBy(String.valueOf(user.getUserId()));
        company.setUpdateTime(DateUtils.getNowDate());
        return companyMapper.updateById(company);
    }

    private void companyNatureHandler(Company company) {
        String identifier = company.getIdentifier();
        String companyName = company.getName().trim();
        if (StrUtil.isNotBlank(identifier) && !"-".equals(identifier)) {
            List<Tag> tagList = tagMapper.selectList(Wrappers.lambdaQuery());
            Map<String, Long> tagNamesMap = tagList.stream().collect(Collectors.toMap(Tag::getName, Tag::getId));

            // 单位类别标签
            String prefix = identifier.trim().substring(0, 2);
            if ("11".equals(prefix)) {
                Long tagId = tagNamesMap.get("机关");
                if (Objects.nonNull(tagId)) {
                    company.setNature1(tagId);
                    company.setNatureName1("机关");
                }
            }
            if ("11".equals(prefix) && companyName.endsWith("人民政府")) {
                Long tagId = tagNamesMap.get("地方政府");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("地方政府");
                }
            }
            if ("11".equals(prefix) && !companyName.endsWith("人民政府")) {
                Long tagId = tagNamesMap.get("内设机构");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("内设机构");
                }
            }
            if ("12".equals(prefix)) {
                Long tagId = tagNamesMap.get("事业单位");
                if (Objects.nonNull(tagId)) {
                    company.setNature1(tagId);
                    company.setNatureName1("事业单位");
                }
            }
            if ("12".equals(prefix) && companyName.endsWith("医院")) {
                Long tagId = tagNamesMap.get("公办医院");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("公办医院");
                }
            }
            if ("12".equals(prefix) && (companyName.endsWith("大学") || companyName.endsWith("学院") || companyName.endsWith("职业技术学院") || companyName.endsWith("职业学院") || companyName.endsWith("高等专科学") || companyName.endsWith("职业技术大学") || companyName.endsWith("职业大学"))) {
                Long tagId = tagNamesMap.get("公办高校");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("公办高校");
                }
            }
            if ("12".equals(prefix) && companyName.endsWith("中学")) {
                Long tagId = tagNamesMap.get("公办中学");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("公办中学");
                }
            }
            if ("12".equals(prefix) && companyName.endsWith("小学")) {
                Long tagId = tagNamesMap.get("公办小学");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("公办小学");
                }
            }
            if ("12".equals(prefix) && (companyName.endsWith("科学院") || companyName.endsWith("科学技术中心") || companyName.endsWith("研究院") || companyName.endsWith("研究所"))) {
                Long tagId = tagNamesMap.get("公办科研机构");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("公办科研机构");
                }
            }
            if ("12".equals(prefix) && companyName.endsWith("管理委员会")) {
                Long tagId = tagNamesMap.get("园区管委会");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("园区管委会");
                }
            }
            if ("51".equals(prefix)) {
                Long tagId = tagNamesMap.get("社会团体");
                if (Objects.nonNull(tagId)) {
                    company.setNature1(tagId);
                    company.setNatureName1("社会团体");
                }
            }
            if ("51".equals(prefix) && companyName.endsWith("协会")) {
                Long tagId = tagNamesMap.get("协会");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("协会");
                }
            }
            if ("51".equals(prefix) && companyName.endsWith("学会")) {
                Long tagId = tagNamesMap.get("学会");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("学会");
                }
            }
            if ("51".equals(prefix) && companyName.endsWith("研究会")) {
                Long tagId = tagNamesMap.get("研究会");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("研究会");
                }
            }
            if ("51".equals(prefix) && companyName.endsWith("战略联盟")) {
                Long tagId = tagNamesMap.get("战略联盟");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("战略联盟");
                }
            }
            if ("52".equals(prefix)) {
                Long tagId = tagNamesMap.get("民办非企业");
                if (Objects.nonNull(tagId)) {
                    company.setNature1(tagId);
                    company.setNatureName1("民办非企业");
                }
            }
            if ("52".equals(prefix) && companyName.endsWith("医院")) {
                Long tagId = tagNamesMap.get("民办医院");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("民办医院");
                }
            }
            if ("52".equals(prefix) && (companyName.endsWith("大学") || companyName.endsWith("学院") || companyName.endsWith("职业技术学院") || companyName.endsWith("职业学院") || companyName.endsWith("高等专科学") || companyName.endsWith("职业技术大学") || companyName.endsWith("职业大学"))) {
                Long tagId = tagNamesMap.get("民办高校");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("民办高校");
                }
            }
            if ("52".equals(prefix) && companyName.endsWith("中学")) {
                Long tagId = tagNamesMap.get("民办中学");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("民办中学");
                }
            }
            if ("52".equals(prefix) && companyName.endsWith("小学")) {
                Long tagId = tagNamesMap.get("民办小学");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("民办小学");
                }
            }
            if ("52".equals(prefix) && (companyName.endsWith("科学院") || companyName.endsWith("科学技术中心") || companyName.endsWith("研究院") || companyName.endsWith("研究所"))) {
                Long tagId = tagNamesMap.get("民办科研机构");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("民办科研机构");
                }
            }
            if ("91".equals(prefix)) {
                Long tagId = tagNamesMap.get("企业");
                if (Objects.nonNull(tagId)) {
                    company.setNature1(tagId);
                    company.setNatureName1("企业");
                }
            }

            List<String> industryList = Arrays.asList((company.getIndustryName1() + "," + company.getIndustryName2() + "," + company.getIndustryName3() + "," + company.getIndustryName4()).split(","));
            if ("91".equals(prefix) && !industryList.contains("72商务服务业") && !industryList.contains("74专业技术服务业") && !industryList.contains("75科技推广和应用服务业")) {
                Long tagId = tagNamesMap.get("常规企业");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("常规企业");
                }
            }
            if ("91".equals(prefix) && industryList.contains("72商务服务业") || industryList.contains("74专业技术服务业") || industryList.contains("75科技推广和应用服务业")) {
                Long tagId = tagNamesMap.get("科技服务企业");
                if (Objects.nonNull(tagId)) {
                    company.setNature2(tagId);
                    company.setNatureName2("科技服务企业");
                }
            }
            if ("92".equals(prefix)) {
                Long tagId = tagNamesMap.get("个体户");
                if (Objects.nonNull(tagId)) {
                    company.setNature1(tagId);
                    company.setNatureName1("个体户");
                }
            }
            if ("93".equals(prefix)) {
                Long tagId = tagNamesMap.get("农民专业合作社");
                if (Objects.nonNull(tagId)) {
                    company.setNature1(tagId);
                    company.setNatureName1("农民专业合作社");
                }

            }
        }
    }

    /**
     * 删除公司信息
     *
     * @param id 公司主键
     * @return 结果
     */
    @Override
    public int deleteCompanyById(Long id) {
        Company company = companyMapper.selectById(id);
//        company.setisde
        return companyMapper.updateById(company);
    }

    @Override
    public List<Company> searchCompanyList(Company company) {
        return companyMapper.searchCompanyList(company);
    }

    /**
     * 查询企业信息
     *
     * @param id 公司主键
     * @return 公司
     */
    @Override
    public KeywordSearchDetailsVO selectCompanyInfo(String name) {

        KeywordSearchDetailsVO company = companyMapper.selectCompanyInfo(name);
        if (Objects.nonNull(company)) {
            String areaNameStr = company.getProvinceName();
            if (StrUtil.isNotBlank(company.getCityName())) {
                areaNameStr += "-" + company.getCityName();
            }
            if (StrUtil.isNotBlank(company.getDistrictName())) {
                areaNameStr += "-" + company.getDistrictName();
            }
            company.setAreaNameStr(areaNameStr);

            String industryNameStr = company.getIndustryName1();
            if (StrUtil.isNotBlank(company.getIndustryName2())) {
                industryNameStr += "-" + company.getIndustryName2();
            }
            if (StrUtil.isNotBlank(company.getIndustryName3())) {
                industryNameStr += "-" + company.getIndustryName3();
            }
            if (StrUtil.isNotBlank(company.getIndustryName4())) {
                industryNameStr += "-" + company.getIndustryName4();
            }
            company.setIndustryNameStr(industryNameStr);

            String parkNameStr = company.getParkName1();
            if (StrUtil.isNotBlank(company.getParkName2())) {
                parkNameStr += "-" + company.getParkName2();
            }
            if (StrUtil.isNotBlank(company.getParkName3())) {
                parkNameStr += "-" + company.getParkName3();
            }
            if (StrUtil.isNotBlank(company.getParkName4())) {
                parkNameStr += "-" + company.getParkName4();
            }
            if (StrUtil.isNotBlank(company.getParkName5())) {
                parkNameStr += "-" + company.getParkName5();
            }
            if (StrUtil.isNotBlank(company.getParkName6())) {
                parkNameStr += "-" + company.getParkName6();
            }

            company.setParkNameStr(parkNameStr);

        }
        return company;
    }


    @Override
    public List<CompanyPatent> getCompanyPatentList(Long companyId) {
        List<CompanyPatent> result = companyPatentMapper.selectList(Wrappers.<CompanyPatent>lambdaQuery().eq(CompanyPatent::getCompanyId, companyId));
        int startNo = 0;
        for (CompanyPatent item : result) {
            item.setNo(startNo + 1);
            startNo++;
        }
        return result;
    }

    @Override
    public List<CompanyAccs> getCompanyAccsList(Long companyId) {
        List<CompanyAccs> result = companyAccsMapper.selectList(Wrappers.<CompanyAccs>lambdaQuery().eq(CompanyAccs::getCompanyId, companyId));
        int startNo = 0;
        for (CompanyAccs item : result) {
            item.setNo(startNo + 1);
            startNo++;
        }
        return result;
    }

    @Override
    public CompanyPatent getCompanyPatent(Long id) {
        return companyPatentMapper.selectById(id);
    }

    @Override
    public CompanyAccs getCompanyAccs(Long id) {
        return companyAccsMapper.selectById(id);
    }

    @Override
    public void insertCompanyPatent(CompanyPatent companyPatent) {
        companyPatentMapper.insert(companyPatent);
    }

    @Override
    public void insertCompanyAccs(CompanyAccs companyAccs) {
        companyAccsMapper.insert(companyAccs);
    }

    @Override
    public void updateCompanyPatent(CompanyPatent companyPatent) {
        companyPatentMapper.updateById(companyPatent);
    }

    @Override
    public void updateCompanyAccs(CompanyAccs companyAccs) {
        companyAccsMapper.updateById(companyAccs);
    }

    @Override
    public void delCompanyPatent(Long id) {
        companyPatentMapper.deleteById(id);
    }

    @Override
    public void delCompanyAccs(Long id) {
        companyAccsMapper.deleteById(id);
    }

    public Company getQccCompany(String companyName) {
        Company company = companyMapper.selectOne(Wrappers.<Company>lambdaQuery().eq(Company::getName, companyName));
        if (Objects.nonNull(company)) {
            if (1 == company.getGetApi()) {
                return company;
            }
        }
        String reqInterNme = "http://api.qichacha.com/EnterpriseInfo/Verify";
        String paramStr = "searchKey=" + companyName;
        String[] autherHeader = RandomAuthentHeader();
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("Token", autherHeader[0]);
        headerMap.put("Timespan", autherHeader[1]);

        final String reqUri = reqInterNme.concat("?key=").concat(appkey).concat("&").concat(paramStr);

        HttpRequest request = HttpRequest.get(reqUri).addHeaders(headerMap);
        HttpResponse response = request.execute();
        String result = response.body();
//        String result = "{\"Status\":\"200\",\"Message\":\"【有效请求】查询成功\",\"OrderNumber\":\"ENTERPRISEINFO2024010811391581233873\",\"Result\":{\"VerifyResult\":1,\"Data\":{\"KeyNo\":\"2vlb5ybbamvha9mj5pki5rblhjje5jephj\",\"Name\":\"湖南标点科技服务有限公司\",\"CreditCode\":\"91430100MA4Q7RRH04\",\"OperName\":\"杨达\",\"Status\":\"存续（在营、开业、在册）\",\"StartDate\":\"2019-01-08\",\"RegistCapi\":\"200万元人民币\",\"RealCapi\":\"\",\"OrgNo\":\"MA4Q7RRH-0\",\"No\":\"\",\"TaxNo\":\"91430100MA4Q7RRH04\",\"EconKind\":\"有限责任公司（自然人投资或控股）\",\"TermStart\":\"2019-01-08\",\"TermEnd\":\"2069-01-07\",\"TaxpayerType\":\"小规模纳税人\",\"PersonScope\":\"少于50人\",\"InsuredCount\":\"2\",\"CheckDate\":\"2020-06-03\",\"AreaCode\":\"430104\",\"Area\":{\"Province\":\"湖南省\",\"City\":\"长沙市\",\"County\":\"岳麓区\"},\"BelongOrg\":\"长沙市工商行政管理局高新技术产业开发区分局\",\"ImExCode\":\"\",\"Industry\":{\"IndustryCode\":\"I\",\"Industry\":\"信息传输、软件和信息技术服务业\",\"SubIndustryCode\":\"\",\"SubIndustry\":\"\",\"MiddleCategoryCode\":\"\",\"MiddleCategory\":\"\",\"SmallCategoryCode\":\"\",\"SmallCategory\":\"\"},\"EnglishName\":\"Hunan Punctuation Technology Service Co., Ltd.\",\"Address\":\"长沙高新开发区延农路72号九天银河产业园4号栋胜利者同盟大楼6楼B6115房\",\"AnnualAddress\":\"\",\"Scope\":\"科技中介服务;科技信息咨询服务;科技成果鉴定服务;机械技术推广服务;新材料技术推广服务;信息电子技术服务;生物技术推广服务;医疗器械技术推广服务;新能源技术推广;节能技术推广服务;环保技术推广服务;农林牧渔技术推广服务;生物防治技术推广服务;电子商务平台的开发建设;计算机网络平台的开发及建设;软件开发系统集成服务;软件技术服务;信息技术咨询服务;软件技术转让;学术交流活动的组织;培训活动的组织;会议、展览及相关服务;众创空间的建设、运营和管理;科技项目代理服务、评估服务;支撑软件、应用软件的开发。（依法须经批准的项目,经相关部门批准后方可开展经营活动,未经批准不得从事P2P网贷、股权众筹、互联网保险、资管及跨界从事金融、第三方支付、虚拟货币交易、ICO、非法外汇等互联网金融业务）\",\"EntType\":\"0\",\"ImageUrl\":\"https://image.qcc.com/logo/EntImage.png\",\"RevokeInfo\":null,\"OriginalName\":null,\"StockInfo\":null,\"ContactInfo\":{\"WebSiteList\":[\"touce.com.cn\"],\"Email\":\"1546118975@qq.com\",\"MoreEmailList\":null,\"Tel\":\"0731-89926190\",\"MoreTelList\":[{\"Tel\":\"18907485158\",\"Source\":\"2022年报\"}]},\"LongLat\":{\"Longitude\":\"112.879927\",\"Latitude\":\"28.240763\"},\"BankInfo\":{\"Bank\":\"招商银行股份有限公司长沙大河西先导区支行\",\"BankAccount\":\"731907351010902\",\"Name\":\"湖南标点科技服务有限公司\",\"CreditCode\":\"91430100MA4Q7RRH04\",\"Address\":\"长沙高新开发区延农路72号九天银河产业园4号栋胜利者同盟大楼6楼B6115房\",\"Tel\":\"18907485158\"},\"IsSmall\":\"1\",\"Scale\":\"S\",\"QccIndustry\":{\"AName\":\"信息技术\",\"BName\":\"\",\"CName\":\"\",\"DName\":\"\"},\"IsOfficialEnglish\":\"0\"}}}";
        QccCompany qccCompany = JSONObject.parseObject(result, QccCompany.class);

        if ("200".equals(qccCompany.getStatus())) {
            if (1 == qccCompany.getResult().getVerifyResult()) {

                List<ParkArea> areaList = parkAreaMapper.selectList(Wrappers.<ParkArea>lambdaQuery());
                Map<String, Long> areaMap = areaList.stream().filter(item -> !item.getName().equals("非园区")).collect(Collectors.toMap(ParkArea::getName, ParkArea::getId));

                if (Objects.isNull(company)) {
                    company = new Company();
                }
                QccCompany.ResultDTO.DataDTO qccCompanyData = qccCompany.getResult().getData();
                company.setApiData(result);
                if (Objects.nonNull(qccCompanyData.getIndustry())) {
                    company.setIndustryName1(qccCompanyData.getIndustry().getIndustry());
                    company.setIndustryName2(qccCompanyData.getIndustry().getSubIndustry());
                    company.setIndustryName3(qccCompanyData.getIndustry().getMiddleCategory());
                    company.setIndustryName4(qccCompanyData.getIndustry().getSmallCategory());
                }

                // 行业
                List<String> industryIds = Lists.newArrayList();
                if (StrUtil.isNotBlank(company.getIndustryName4())) {
                    Industry industry4 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery()
                            .eq(Industry::getName, company.getIndustryName4())
                            .eq(Industry::getIsDeleted, 0)
                            .eq(Industry::getGrade, 4));
                    company.setIndustry4(industry4.getId());
                }
                if (StrUtil.isNotBlank(company.getIndustryName3())) {
                    Industry industry3 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery()
                            .eq(Industry::getName, company.getIndustryName3())
                            .eq(Industry::getIsDeleted, 0)
                            .eq(Industry::getGrade, 3));
                    company.setIndustry3(industry3.getId());
                }
                if (StrUtil.isNotBlank(company.getIndustryName2())) {
                    Industry industry2 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery()
                            .eq(Industry::getName, company.getIndustryName2())
                            .eq(Industry::getIsDeleted, 0)
                            .eq(Industry::getGrade, 2));
                    company.setIndustry2(industry2.getId());
                }
                if (StrUtil.isNotBlank(company.getIndustryName1())) {
                    Industry industry1 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery()
                            .eq(Industry::getName, company.getIndustryName1())
                            .eq(Industry::getIsDeleted, 0)
                            .eq(Industry::getGrade, 1));
                    company.setIndustry1(industry1.getId());
                }
                if (Objects.nonNull(company.getIndustry1())) {
                    industryIds.add(String.valueOf(company.getIndustry1()));
                }
                if (Objects.nonNull(company.getIndustry2())) {
                    industryIds.add(String.valueOf(company.getIndustry2()));
                }
                if (Objects.nonNull(company.getIndustry3())) {
                    industryIds.add(String.valueOf(company.getIndustry3()));
                }
                if (Objects.nonNull(company.getIndustry4())) {
                    industryIds.add(String.valueOf(company.getIndustry4()));
                }

                company.setIndustryId(String.join(",", industryIds));
                company.setMakesOffer(qccCompanyData.getScope());

                // 参保人数
                List<QccCompany.ResultDTO.DataDTO.OriginalNameDTO> originalNameDTOList = qccCompanyData.getOriginalName();
                if (CollUtil.isNotEmpty(originalNameDTOList)) {
                    List<String> originalNameList = Lists.newArrayList();
                    for (int i = 0; i < originalNameDTOList.size(); i++) {
                        if (i == originalNameDTOList.size() - 1) {
                            originalNameList.add(originalNameDTOList.get(i).getName() + "（" + qccCompanyData.getStartDate() + " 至 " + originalNameDTOList.get(i).getChangeDate() + "）");
                        } else {
                            originalNameList.add(originalNameDTOList.get(i).getName() + "（" + originalNameDTOList.get(i + 1).getChangeDate() + " 至 " + originalNameDTOList.get(i).getChangeDate() + "）");
                        }
                    }
                    company.setHistoryName(String.join(";", originalNameList));
                }
                if (StrUtil.isNotBlank(qccCompanyData.getInsuredCount())) {
                    company.setCbrs(Integer.parseInt(qccCompanyData.getInsuredCount()));
                }
                company.setGetApi(1L);
                if (qccCompanyData.getStatus().contains("存续")) {
                    company.setStatus("1");
                } else if (qccCompanyData.getStatus().contains("在业")) {
                    company.setStatus("2");
                } else if (qccCompanyData.getStatus().contains("吊销")) {
                    company.setStatus("3");
                } else if (qccCompanyData.getStatus().contains("注销")) {
                    company.setStatus("4");
                } else if (qccCompanyData.getStatus().contains("迁入")) {
                    company.setStatus("5");
                } else if (qccCompanyData.getStatus().contains("迁出")) {
                    company.setStatus("6");
                } else if (qccCompanyData.getStatus().contains("停业")) {
                    company.setStatus("7");
                } else if (qccCompanyData.getStatus().contains("清算")) {
                    company.setStatus("8");
                }

                if (Objects.isNull(company.getId())) {
                    company.setName(qccCompanyData.getName());
                    company.setFounder(qccCompanyData.getOperName());
                    if (StrUtil.isNotBlank(qccCompanyData.getRegistCapi())) {
                        if (qccCompanyData.getRegistCapi().contains("人民币")) {
                            company.setRegisteredCapital(qccCompanyData.getRegistCapi().replace("万人民币", ""));
                            company.setCurrency("1");
                        } else if (qccCompanyData.getRegistCapi().contains("欧元")) {
                            company.setRegisteredCapital(qccCompanyData.getRegistCapi().replace("万欧元", ""));
                            company.setCurrency("2");
                        } else if (qccCompanyData.getRegistCapi().contains("美元")) {
                            company.setRegisteredCapital(qccCompanyData.getRegistCapi().replace("万美元", ""));
                            company.setCurrency("3");
                        }
                    }
                    if (StrUtil.isNotBlank(qccCompanyData.getRealCapi())) {
                        if (qccCompanyData.getRealCapi().contains("人民币")) {
                            company.setOutCapital(qccCompanyData.getRealCapi().replace("万人民币", ""));
                            company.setCurrency("1");
                        } else if (qccCompanyData.getRealCapi().contains("欧元")) {
                            company.setOutCapital(qccCompanyData.getRealCapi().replace("万欧元", ""));
                            company.setCurrency("2");
                        } else if (qccCompanyData.getRealCapi().contains("美元")) {
                            company.setOutCapital(qccCompanyData.getRealCapi().replace("万美元", ""));
                            company.setCurrency("3");
                        }
                    }
                    company.setFoundingDate(qccCompanyData.getStartDate());
                    company.setIdentifier(qccCompanyData.getCreditCode());
                    company.setRegistrationNumber(qccCompanyData.getNo());
                    company.setOrganizationalCode(qccCompanyData.getOrgNo());
                    company.setTin(qccCompanyData.getTaxNo());
                    company.setEnterpriseType(qccCompanyData.getEconKind());
                    company.setApprovalDate(qccCompanyData.getCheckDate());
                    company.setRegistrationAuthority(qccCompanyData.getBelongOrg());
                    List<String> parkAreaIds = Lists.newArrayList();
                    parkAreaIds.add("985");
                    if (StrUtil.isNotBlank(qccCompanyData.getArea().getProvince())) {
                        company.setProvince(areaMap.get(qccCompanyData.getArea().getProvince()));
                        company.setProvinceName(qccCompanyData.getArea().getProvince());
                        if(Objects.nonNull(company.getProvince())) {
                            parkAreaIds.add(String.valueOf(company.getProvince()));
                        }
                    }
                    if (StrUtil.isNotBlank(qccCompanyData.getArea().getCity())) {
                        company.setCity(areaMap.get(qccCompanyData.getArea().getCity()));
                        company.setCityName(qccCompanyData.getArea().getCity());
                        if(Objects.nonNull(company.getCity())) {
                            parkAreaIds.add(String.valueOf(company.getCity()));
                        }
                    }
                    if (StrUtil.isNotBlank(qccCompanyData.getArea().getCounty())) {
                        company.setDistrict(areaMap.get(qccCompanyData.getArea().getCounty()));
                        company.setDistrictName(qccCompanyData.getArea().getCounty());
                        if(Objects.nonNull(company.getDistrict())) {
                            parkAreaIds.add(String.valueOf(company.getDistrict()));
                        }
                    }

                    // 园区
                    if (CollUtil.isNotEmpty(parkAreaIds)) {
                        if (parkAreaIds.size() > 0) {
                            Long park1 = Long.parseLong(parkAreaIds.get(0));
                            company.setPark1(park1);
                            company.setLastPark(park1);
                            company.setParkName1("全国");
                            company.setLastParkName("全国");
                        }
                        if (parkAreaIds.size() > 1) {
                            Long park2 = Long.parseLong(parkAreaIds.get(1));
                            company.setPark2(park2);
                            company.setLastPark(park2);
                            company.setParkName2(company.getProvinceName());
                            company.setLastParkName(company.getProvinceName());
                        }
                        if (parkAreaIds.size() > 2) {
                            Long park3 = Long.parseLong(parkAreaIds.get(2));
                            company.setPark3(park3);
                            company.setLastPark(park3);
                            company.setParkName3(company.getCityName());
                            company.setLastParkName(company.getCityName());
                        }
                        if (parkAreaIds.size() > 3) {
                            Long park4 = Long.parseLong(parkAreaIds.get(3));
                            company.setPark4(park4);
                            company.setLastPark(park4);
                            company.setParkName4(company.getDistrictName());
                            company.setLastParkName(company.getDistrictName());
                        }
                        company.setParkAreaId(String.join(",", parkAreaIds));
                    }

                    company.setPersonnel(qccCompanyData.getPersonScope());
                    company.setBusinessTerm(qccCompanyData.getTermStart() + "-" + qccCompanyData.getTermEnd());
                    company.setAddress(qccCompanyData.getAddress());
                    company.setCreateTime(new Date());
                    company.setUpdateTime(new Date());
                    // 性质处理
                    companyNatureHandler(company);
                    companyMapper.insert(company);
                } else {
                    companyMapper.updateById(company);
                }
            }
        }
        return company;
    }


    public void importCompanyData(List<CompanyExcel> companyList) {

        SysUser user = getLoginUser().getUser();
        if (StringUtils.isNull(companyList) || companyList.size() == 0) {
            throw new ServiceException("导入数据不能为空！");
        }


        executorService.execute(() -> {
            List<ParkArea> areaList = parkAreaMapper.selectList(Wrappers.<ParkArea>lambdaQuery());
            Map<String, Long> areaMap = areaList.stream().filter(item -> !item.getName().equals("非园区")).collect(Collectors.toMap(ParkArea::getName, ParkArea::getId));

            for (CompanyExcel companyExcel : companyList) {
                Company company = companyMapper.selectOne(Wrappers.<Company>lambdaQuery().eq(Company::getName, companyExcel.getCompanyName()));
                if (Objects.isNull(company)) {
                    company = new Company();
                    company.setCreateTime(new Date());
                    company.setCreateBy(String.valueOf(user.getUserId()));
                }
                company.setName(companyExcel.getCompanyName());
                company.setAddress(companyExcel.getAddress());
                String industryName = companyExcel.getIndustry();
                if (StrUtil.isNotBlank(industryName)) {
                    String[] industryNames = industryName.split(">");
                    // 行业
                    List<String> industryIds = Lists.newArrayList();

                    if (industryNames.length > 0) {
                        Industry industry1 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery().select(Industry::getId, Industry::getName)
                                .eq(Industry::getName, industryNames[0])
                                .eq(Industry::getIsDeleted, 0)
                                .eq(Industry::getGrade, 1));
                        if (Objects.nonNull(industry1)) {
                            company.setIndustry1(industry1.getId());
                            company.setIndustryName1(industryNames[0]);
                            industryIds.add(String.valueOf(company.getIndustry1()));
                        }
                    }
                    if (industryNames.length > 1) {
                        if (StrUtil.isNotBlank(company.getIndustryName1())) {
                            Industry industry2 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery()
                                    .eq(Industry::getName, industryNames[1])
                                    .eq(Industry::getIsDeleted, 0)
                                    .eq(Industry::getGrade, 2));
                            if (Objects.isNull(industry2)) {
                                company.setIndustry1(null);
                                company.setIndustryName1("");
                                industryIds.clear();
                            } else {
                                company.setIndustry2(industry2.getId());
                                company.setIndustryName2(industryNames[1]);
                                industryIds.add(String.valueOf(company.getIndustry2()));
                            }
                        }
                    }
                    if (industryNames.length > 2) {
                        if (StrUtil.isNotBlank(company.getIndustryName1())) {
                            Industry industry3 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery()
                                    .eq(Industry::getName, industryNames[2])
                                    .eq(Industry::getIsDeleted, 0)
                                    .eq(Industry::getGrade, 3));
                            if (Objects.isNull(industry3)) {
                                company.setIndustry1(null);
                                company.setIndustryName1("");
                                company.setIndustry2(null);
                                company.setIndustryName2("");
                                industryIds.clear();
                            } else {
                                company.setIndustry3(industry3.getId());
                                company.setIndustryName3(industryNames[2]);
                                industryIds.add(String.valueOf(company.getIndustry3()));
                            }
                        }
                    }
                    if (industryNames.length > 3) {
                        if (StrUtil.isNotBlank(company.getIndustryName1())) {
                            Industry industry4 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery()
                                    .eq(Industry::getName, industryNames[3])
                                    .eq(Industry::getIsDeleted, 0)
                                    .eq(Industry::getGrade, 4));
                            if (Objects.isNull(industry4)) {
                                company.setIndustry1(null);
                                company.setIndustryName1("");
                                company.setIndustry2(null);
                                company.setIndustryName2("");
                                company.setIndustry3(null);
                                company.setIndustryName3("");
                                industryIds.clear();
                            } else {
                                company.setIndustry4(industry4.getId());
                                company.setIndustryName4(industryNames[3]);
                                industryIds.add(String.valueOf(company.getIndustry4()));
                            }
                        }
                    }
                    if (CollUtil.isNotEmpty(industryIds)) {
                        company.setIndustryId(String.join(",", industryIds));
                    }
                }

                // 园区
                String park = companyExcel.getPark();
                if (StrUtil.isNotBlank(park)) {
                    List<String> parkAreaIds = Lists.newArrayList();
                    String[] parkNames = park.split(">");
                    if (parkNames.length > 0) {
                        company.setPark1(985L);
                        company.setLastPark(985L);
                        company.setParkName1("全国");
                        company.setLastParkName("全国");
                        parkAreaIds.add("985");

                        Long park2 = areaMap.get(parkNames[0]);
                        company.setPark2(park2);
                        company.setLastPark(park2);
                        company.setParkName2(parkNames[0]);
                        company.setLastParkName(parkNames[0]);
                        if (Objects.nonNull(park2)) {
                            parkAreaIds.add(String.valueOf(park2));
                        }
                    }

                    if (parkNames.length > 1) {
                        Long park3 = areaMap.get(parkNames[1]);
                        company.setPark3(park3);
                        company.setLastPark(park3);
                        company.setParkName3(parkNames[1]);
                        company.setLastParkName(parkNames[1]);
                        if (Objects.nonNull(park3)) {
                            parkAreaIds.add(String.valueOf(park3));
                        }
                    }
                    if (parkNames.length > 2) {
                        Long park4 = areaMap.get(parkNames[2]);
                        company.setPark4(park4);
                        company.setLastPark(park4);
                        company.setParkName4(parkNames[2]);
                        company.setLastParkName(parkNames[2]);
                        if (Objects.nonNull(park4)) {
                            parkAreaIds.add(String.valueOf(park4));
                        }
                    }
                    if (parkNames.length > 3) {
                        Long park5 = areaMap.get(parkNames[3]);
                        company.setPark5(park5);
                        company.setLastPark(park5);
                        company.setParkName5(parkNames[3]);
                        company.setLastParkName(parkNames[3]);
                        if (Objects.nonNull(park5)) {
                            parkAreaIds.add(String.valueOf(park5));
                        }
                    }
                    if (parkNames.length > 4) {
                        Long park6 = areaMap.get(parkNames[4]);
                        company.setPark6(park6);
                        company.setLastPark(park6);
                        company.setParkName6(parkNames[4]);
                        company.setLastParkName(parkNames[4]);
                        if (Objects.nonNull(park6)) {
                            parkAreaIds.add(String.valueOf(park6));
                        }
                    }
                    company.setParkAreaId(String.join(",", parkAreaIds));
                }

                if (StrUtil.isNotBlank(companyExcel.getInsuredCount()) && !"-".equals(companyExcel.getInsuredCount())) {
                    company.setCbrs(Integer.parseInt(companyExcel.getInsuredCount()));
                }

                company.setMakesOffer(companyExcel.getMakesOffer());
                String historyName = companyExcel.getHistoryName();
                if (historyName.contains(",")) {
                    historyName = historyName.replaceAll(",",";");
                }
                if (historyName.contains("(")) {
                    historyName = historyName.replaceAll("\\(","（");
                }
                if (historyName.contains(")")) {
                    historyName = historyName.replaceAll("\\)","）");
                }
                company.setHistoryName(historyName);
                company.setFounder(companyExcel.getFounder());
                company.setFoundingDate(companyExcel.getFoundingDate());
                if (companyExcel.getStatus().contains("存续")) {
                    company.setStatus("1");
                } else if (companyExcel.getStatus().contains("在业")) {
                    company.setStatus("2");
                } else if (companyExcel.getStatus().contains("吊销")) {
                    company.setStatus("3");
                } else if (companyExcel.getStatus().contains("注销")) {
                    company.setStatus("4");
                } else if (companyExcel.getStatus().contains("迁入")) {
                    company.setStatus("5");
                } else if (companyExcel.getStatus().contains("迁出")) {
                    company.setStatus("6");
                } else if (companyExcel.getStatus().contains("停业")) {
                    company.setStatus("7");
                } else if (companyExcel.getStatus().contains("清算")) {
                    company.setStatus("8");
                }
                company.setIdentifier(companyExcel.getIdentifier());
                company.setRegistrationAuthority(companyExcel.getRegistrationAuthority());

                if (StrUtil.isNotBlank(companyExcel.getRegisteredCapital()) && !"-".equals(companyExcel.getRegisteredCapital())) {
                    if (companyExcel.getRegisteredCapital().contains("万美元")) {
                        company.setRegisteredCapital(companyExcel.getRegisteredCapital().substring(0, companyExcel.getRegisteredCapital().indexOf(">")));
                        company.setCurrency("3");
                    } else if (companyExcel.getRegisteredCapital().contains("万欧元")) {
                        company.setRegisteredCapital(companyExcel.getRegisteredCapital().substring(0, companyExcel.getRegisteredCapital().indexOf(">")));
                        company.setCurrency("2");
                    } else {
                        company.setRegisteredCapital(companyExcel.getRegisteredCapital());
                        company.setCurrency("1");
                    }
                }
                if (StrUtil.isNotBlank(companyExcel.getOutCapital()) && !"-".equals(companyExcel.getOutCapital())) {
                    if (companyExcel.getOutCapital().contains("万美元")) {
                        company.setOutCapital(companyExcel.getOutCapital().substring(0, companyExcel.getOutCapital().indexOf(">")));
                        company.setOutCurrency("3");
                    } else if (companyExcel.getOutCapital().contains("万欧元")) {
                        company.setOutCapital(companyExcel.getOutCapital().substring(0, companyExcel.getOutCapital().indexOf(">")));
                        company.setOutCurrency("2");
                    } else {
                        company.setOutCapital(companyExcel.getOutCapital());
                        company.setOutCurrency("1");
                    }
                }
                if (StrUtil.isBlank(company.getStatus())
                        || StrUtil.isBlank(company.getFounder())
                        || StrUtil.isBlank(company.getFoundingDate())
                        || StrUtil.isBlank(company.getIdentifier())
                        || StrUtil.isBlank(company.getRegisteredCapital())
                        || Objects.isNull(company.getLastPark())
                        || StrUtil.isBlank(company.getRegistrationAuthority())
                        || Objects.isNull(company.getIndustry1())
                        || StrUtil.isBlank(company.getAddress())
                        || StrUtil.isBlank(company.getMakesOffer())) {
                    company.setWarn("1");
                }
                // 性质处理
                companyNatureHandler(company);
                if (Objects.isNull(company.getId())) {
                    companyMapper.insert(company);
                } else {
                    company.setUpdateTime(new Date());
                    company.setUpdateBy(String.valueOf(user.getUserId()));
                    companyMapper.updateById(company);
                }

            }
        });
    }

    public void importQccCompanyData(List<QccCompanyExcel> companyList) {

        SysUser user = getLoginUser().getUser();
        if (StringUtils.isNull(companyList) || companyList.size() == 0) {
            throw new ServiceException("导入数据不能为空！");
        }


        executorService.execute(() -> {
            List<ParkArea> areaList = parkAreaMapper.selectList(Wrappers.<ParkArea>lambdaQuery());
            Map<String, Long> areaMap = areaList.stream().filter(item -> !item.getName().equals("非园区")).collect(Collectors.toMap(ParkArea::getName, ParkArea::getId));

            for (QccCompanyExcel companyExcel : companyList) {
                Company company = companyMapper.selectOne(Wrappers.<Company>lambdaQuery().eq(Company::getName, companyExcel.getCompanyName()));
                if (Objects.isNull(company)) {
                    company = new Company();
                    company.setCreateTime(new Date());
                    company.setCreateBy(String.valueOf(user.getUserId()));
                }
                company.setName(companyExcel.getCompanyName());
                company.setAddress(companyExcel.getAddress());
                // 行业
                List<String> industryIds = Lists.newArrayList();

                String industryName1 = companyExcel.getIndustry1();
                if (StrUtil.isNotBlank(industryName1)) {

                    Industry industry1 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery().select(Industry::getId, Industry::getName)
                            .eq(Industry::getName, industryName1)
                            .eq(Industry::getIsDeleted, 0)
                            .eq(Industry::getGrade, 1));
                    if (Objects.nonNull(industry1)) {
                        company.setIndustry1(industry1.getId());
                        company.setIndustryName1(industryName1);
                        industryIds.add(String.valueOf(company.getIndustry1()));
                    }
                }
                String industryName2 = companyExcel.getIndustry2();
                if (StrUtil.isNotBlank(industryName2)) {
                    if (StrUtil.isNotBlank(company.getIndustryName1())) {
                        Industry industry2 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery()
                                .eq(Industry::getName, industryName2)
                                .eq(Industry::getIsDeleted, 0)
                                .eq(Industry::getGrade, 2));
                        if (Objects.isNull(industry2)) {
                            company.setIndustry1(null);
                            company.setIndustryName1("");
                            industryIds.clear();
                        } else {
                            company.setIndustry2(industry2.getId());
                            company.setIndustryName2(industryName2);
                            industryIds.add(String.valueOf(company.getIndustry2()));
                        }
                    }
                }
                String industryName3 = companyExcel.getIndustry3();
                if (StrUtil.isNotBlank(industryName3)) {
                    if (StrUtil.isNotBlank(company.getIndustryName1())) {
                        Industry industry3 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery()
                                .eq(Industry::getName, industryName3)
                                .eq(Industry::getIsDeleted, 0)
                                .eq(Industry::getGrade, 3));
                        if (Objects.isNull(industry3)) {
                            company.setIndustry1(null);
                            company.setIndustryName1("");
                            company.setIndustry2(null);
                            company.setIndustryName2("");
                            industryIds.clear();
                        } else {
                            company.setIndustry3(industry3.getId());
                            company.setIndustryName3(industryName3);
                            industryIds.add(String.valueOf(company.getIndustry3()));
                        }
                    }
                }
                String industryName4 = companyExcel.getIndustry4();
                if (StrUtil.isNotBlank(industryName4)) {
                    if (StrUtil.isNotBlank(company.getIndustryName1())) {
                        Industry industry4 = industryMapper.selectOne(Wrappers.<Industry>lambdaQuery()
                                .eq(Industry::getName, industryName4)
                                .eq(Industry::getIsDeleted, 0)
                                .eq(Industry::getGrade, 4));
                        if (Objects.isNull(industry4)) {
                            company.setIndustry1(null);
                            company.setIndustryName1("");
                            company.setIndustry2(null);
                            company.setIndustryName2("");
                            company.setIndustry3(null);
                            company.setIndustryName3("");
                            industryIds.clear();
                        } else {
                            company.setIndustry4(industry4.getId());
                            company.setIndustryName4(industryName4);
                            industryIds.add(String.valueOf(company.getIndustry4()));
                        }
                    }
                }
                if (CollUtil.isNotEmpty(industryIds)) {
                    company.setIndustryId(String.join(",", industryIds));
                }


                // 园区
                List<String> parkAreaIds = Lists.newArrayList();
                company.setPark1(985L);
                company.setLastPark(985L);
                company.setParkName1("全国");
                company.setLastParkName("全国");
                parkAreaIds.add("985");

                String province = companyExcel.getProvince();
                if (StrUtil.isNotBlank(province)) {
                    Long park2 = areaMap.get(province);
                    company.setPark2(park2);
                    company.setLastPark(park2);
                    company.setParkName2(province);
                    company.setLastParkName(province);
                    if (Objects.nonNull(park2)) {
                        parkAreaIds.add(String.valueOf(park2));
                    }
                }

                String city = companyExcel.getCity();
                if (StrUtil.isNotBlank(city)) {
                    Long park3 = areaMap.get(city);
                    company.setPark3(park3);
                    company.setLastPark(park3);
                    company.setParkName3(city);
                    company.setLastParkName(city);
                    if (Objects.nonNull(park3)) {
                        parkAreaIds.add(String.valueOf(park3));
                    }
                }
                String district = companyExcel.getDistrict();
                if (StrUtil.isNotBlank(district)) {

                    Long park4 = areaMap.get(district);
                    company.setPark4(park4);
                    company.setLastPark(park4);
                    company.setParkName4(district);
                    company.setLastParkName(district);
                    if (Objects.nonNull(park4)) {
                        parkAreaIds.add(String.valueOf(park4));
                    }
                }

                company.setParkAreaId(String.join(",", parkAreaIds));


                if (StrUtil.isNotBlank(companyExcel.getInsuredCount()) && !"-".equals(companyExcel.getInsuredCount())) {
                    company.setCbrs(Integer.parseInt(companyExcel.getInsuredCount()));
                }

                company.setMakesOffer(companyExcel.getMakesOffer());
                String historyName = companyExcel.getHistoryName();
                if (historyName.contains(",")) {
                    historyName = historyName.replaceAll(",",";");
                }
                if (historyName.contains("(")) {
                    historyName = historyName.replaceAll("\\(","（");
                }
                if (historyName.contains(")")) {
                    historyName = historyName.replaceAll("\\)","）");
                }
                company.setHistoryName(historyName);
                company.setFounder(companyExcel.getFounder());
                company.setFoundingDate(companyExcel.getFoundingDate());
                if (companyExcel.getStatus().contains("存续")) {
                    company.setStatus("1");
                } else if (companyExcel.getStatus().contains("在业")) {
                    company.setStatus("2");
                } else if (companyExcel.getStatus().contains("吊销")) {
                    company.setStatus("3");
                } else if (companyExcel.getStatus().contains("注销")) {
                    company.setStatus("4");
                } else if (companyExcel.getStatus().contains("迁入")) {
                    company.setStatus("5");
                } else if (companyExcel.getStatus().contains("迁出")) {
                    company.setStatus("6");
                } else if (companyExcel.getStatus().contains("停业")) {
                    company.setStatus("7");
                } else if (companyExcel.getStatus().contains("清算")) {
                    company.setStatus("8");
                }
                company.setIdentifier(companyExcel.getIdentifier());

                if (StrUtil.isNotBlank(companyExcel.getRegisteredCapital()) && !"-".equals(companyExcel.getRegisteredCapital())) {
                    if (companyExcel.getRegisteredCapital().contains("万美元")) {
                        company.setRegisteredCapital(companyExcel.getRegisteredCapital().substring(0, companyExcel.getRegisteredCapital().indexOf("万")));
                        company.setCurrency("3");
                    } else if (companyExcel.getRegisteredCapital().contains("万欧元")) {
                        company.setRegisteredCapital(companyExcel.getRegisteredCapital().substring(0, companyExcel.getRegisteredCapital().indexOf("万")));
                        company.setCurrency("2");
                    } else {
                        company.setRegisteredCapital(companyExcel.getRegisteredCapital().substring(0, companyExcel.getRegisteredCapital().indexOf("万")));
                        company.setCurrency("1");
                    }
                }
//                if (StrUtil.isNotBlank(companyExcel.getOutCapital()) && !"-".equals(companyExcel.getOutCapital())) {
//                    if (companyExcel.getOutCapital().contains("万美元")) {
//                        company.setOutCapital(companyExcel.getOutCapital().substring(0, companyExcel.getOutCapital().indexOf(">")));
//                        company.setOutCurrency("3");
//                    } else if (companyExcel.getOutCapital().contains("万欧元")) {
//                        company.setOutCapital(companyExcel.getOutCapital().substring(0, companyExcel.getOutCapital().indexOf(">")));
//                        company.setOutCurrency("2");
//                    } else {
//                        company.setOutCapital(companyExcel.getOutCapital());
//                        company.setOutCurrency("1");
//                    }
//                }
                if (StrUtil.isBlank(company.getStatus())
                        || StrUtil.isBlank(company.getFounder())
                        || StrUtil.isBlank(company.getFoundingDate())
                        || StrUtil.isBlank(company.getIdentifier())
                        || StrUtil.isBlank(company.getRegisteredCapital())
                        || Objects.isNull(company.getLastPark())
                        || StrUtil.isBlank(company.getRegistrationAuthority())
                        || Objects.isNull(company.getIndustry1())
                        || StrUtil.isBlank(company.getAddress())
                        || StrUtil.isBlank(company.getMakesOffer())) {
                    company.setWarn("1");
                }
                // 性质处理
                companyNatureHandler(company);
                if (Objects.isNull(company.getId())) {
                    companyMapper.insert(company);
                } else {
                    company.setUpdateTime(new Date());
                    company.setUpdateBy(String.valueOf(user.getUserId()));
                    companyMapper.updateById(company);
                }

            }
        });
    }

    public static void main(String[] args) {

//        String reqInterNme = "http://api.qichacha.com/EnterpriseInfo/Verify";
//        String paramStr = "searchKey=永清环保股份有限公司";
//        String status = "";
//        try {
//            String[] autherHeader = RandomAuthentHeader();
//            Map<String, String> headerMap = new HashMap<>();
//            headerMap.put("Token", autherHeader[0]);
//            headerMap.put("Timespan", autherHeader[1]);
//
//            final String reqUri = reqInterNme.concat("?key=").concat(appkey).concat("&").concat(paramStr);
//
//            HttpRequest request = HttpRequest.get(reqUri).addHeaders(headerMap);
//            HttpResponse response = request.execute();
//            String result = response.body();
//            QccCompany qccCompany = JSONUtil.toBean(result, QccCompany.class);
//            String ss = "{\"Status\":\"200\",\"Message\":\"【有效请求】查询成功\",\"OrderNumber\":\"ENTERPRISEINFO2024010414383412017080\",\"Result\":{\"VerifyResult\":1,\"Data\":{\"KeyNo\":\"65a99ymb9s3vhv9jarhplivjmpkjr9ajep\",\"Name\":\"永清环保股份有限公司\",\"CreditCode\":\"91430000760723375M\",\"OperName\":\"王峰\",\"Status\":\"存续（在营、开业、在册）\",\"StartDate\":\"2004-01-19\",\"RegistCapi\":\"64562.2165万元人民币\",\"RealCapi\":\"64562.2165万元人民币\",\"OrgNo\":\"76072337-5\",\"No\":\"430181000007528\",\"TaxNo\":\"91430000760723375M\",\"EconKind\":\"股份有限公司（上市、自然人投资或控股）\",\"TermStart\":\"2004-01-19\",\"TermEnd\":\"\",\"TaxpayerType\":\"增值税一般纳税人\",\"PersonScope\":\"400-499人\",\"InsuredCount\":\"485\",\"CheckDate\":\"2023-01-10\",\"AreaCode\":\"430181\",\"Area\":{\"Province\":\"湖南省\",\"City\":\"长沙市\",\"County\":\"浏阳市\"},\"BelongOrg\":\"湖南省市场监督管理局\",\"ImExCode\":\"4300760723375\",\"Industry\":{\"IndustryCode\":\"N\",\"Industry\":\"水利、环境和公共设施管理业\",\"SubIndustryCode\":\"77\",\"SubIndustry\":\"生态保护和环境治理业\",\"MiddleCategoryCode\":\"772\",\"MiddleCategory\":\"环境治理业\",\"SmallCategoryCode\":\"7722\",\"SmallCategory\":\"大气污染治理\"},\"EnglishName\":\"Yonker Environmental Protection Co., Ltd.\",\"Address\":\"长沙市浏阳市国家生物医药产业基地（319国道旁）\",\"AnnualAddress\":\"\",\"Scope\":\"大气污染防治、新能源发电、火力发电、污染修复和固体废弃物处理工程的咨询、设计、总承包服务；工程相关的设备销售；环境污染治理设施运营；建设项目环境影响评价；清洁服务；环保制剂（不含危险化学品）研发、生产、销售；环保产品相关咨询服务；商品和技术的进出口业务；垃圾车销售；以自有合法资金（资产）开展大气污染防治、新能源发电、火力发电、污染修复和固体废弃物处理工程投资业务（不得从事股权投资、债权投资、短期财务性投资及面对特定对象开展受托资产管理等金融业务，不得从事吸收存款、集资收款、受托贷款、发行票据、发放贷款等国家金融监管及财政信用业务）；环境卫生管理；市政道路清扫保洁、维护；从事城市生活垃圾经营性清扫、收集、运输服务；从事城市生活垃圾经营性处理服务；垃圾分类服务；绿化管理；物业管理；城市水域垃圾清理；河道保洁；普通货物运输（货运出租、搬场运输除外）。（依法须经批准的项目，经相关部门批准后方可开展经营活动）\",\"EntType\":\"0\",\"ImageUrl\":\"https://image.qcc.com/logo/6a316cd533b85365ee0e08c714f20639.jpg\",\"RevokeInfo\":null,\"OriginalName\":[{\"Name\":\"湖南永清环保股份有限公司\",\"ChangeDate\":\"2012-09-18\"},{\"Name\":\"湖南永清脱硫股份有限公司\",\"ChangeDate\":\"2008-11-10\"}],\"StockInfo\":{\"StockNumber\":\"300187\",\"StockType\":\"A股\"},\"ContactInfo\":{\"WebSiteList\":[\"http://www.yonker.com.cn/\"],\"Email\":\"yonker6688@163.com\",\"MoreEmailList\":null,\"Tel\":\"0731-83506688\",\"MoreTelList\":[{\"Tel\":\"0731-83285599\",\"Source\":\"互联网\"},{\"Tel\":\"0731-4416867\",\"Source\":\"互联网\"}]},\"LongLat\":{\"Longitude\":\"113.418193\",\"Latitude\":\"28.221555\"},\"BankInfo\":{\"Bank\":\"长沙银行曙光支行\",\"BankAccount\":\"800057262108010\",\"Name\":\"永清环保股份有限公司\",\"CreditCode\":\"91430000760723375M\",\"Address\":\"长沙市浏阳市国家生物医药产业基地（319国道旁）\",\"Tel\":\"0731-83506688\"},\"IsSmall\":\"0\",\"Scale\":\"L\",\"QccIndustry\":{\"AName\":\"工业与商业服务\",\"BName\":\"环保\",\"CName\":\"环境治理\",\"DName\":\"固废治理\"},\"IsOfficialEnglish\":\"1\"}}}";
//            System.out.println(JSONObject.parseObject(ss, QccCompany.class));
//            System.out.println(JSONUtil.toBean(ss, QccCompany.class));
//            System.out.println(1);
//        } catch (Exception e1) {
//            e1.printStackTrace();
//        }
    }

    // 获取返回码 Res Code
    static class HttpCodeRegex {
        private static final String ABNORMAL_REGIX = "(101)|(102)";
        private static final Pattern pattern = Pattern.compile(ABNORMAL_REGIX);

        protected static boolean isAbnornalRequest(final String status) {
            return pattern.matcher(status).matches();
        }
    }

    // 获取Auth Code
    protected static final String[] RandomAuthentHeader() {
        String timeSpan = String.valueOf(System.currentTimeMillis() / 1000);
        String[] authentHeaders = new String[]{DigestUtils.md5Hex(appkey.concat(timeSpan).concat(secretKey)).toUpperCase(), timeSpan};
        return authentHeaders;
    }

//    // 解析JSON
//    protected static String FormartJson(String jsonString, String key) throws JSONException {
//        JSONObject jObject = new JSONObject(jsonString);
//        return (String) jObject.get(key);
//    }
//
//    // pretty print 返回值
//    protected static void PrettyPrintJson(String jsonString) throws JSONException {
//        try {
//            ObjectMapper mapper = new ObjectMapper();
//            Object obj = mapper.readValue(jsonString, Object.class);
//            String indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
//            out.println(indented);
//        } catch (JsonProcessingException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }

    public void importData(List<CompanyStd> companyStdList) {

        List<ParkArea> parkAreaList = parkAreaMapper.selectList(Wrappers.<ParkArea>lambdaQuery());
        Map<String, Long> parkAreaMap = parkAreaList.stream().filter(item -> !"其他".equals(item.getName())).collect(Collectors.toMap(ParkArea::getName, ParkArea::getId));

        for (CompanyStd companyStd : companyStdList) {
            if (StrUtil.isNotBlank(companyStd.getParkName1())) {
                companyStd.setPark1(parkAreaMap.get(companyStd.getParkName1()));
                companyStd.setLastPark(companyStd.getPark1());
                companyStd.setLastParkName(companyStd.getParkName1());
            }
            if (StrUtil.isNotBlank(companyStd.getParkName2())) {
                companyStd.setPark2(parkAreaMap.get(companyStd.getParkName2()));
                companyStd.setLastPark(companyStd.getPark2());
                companyStd.setLastParkName(companyStd.getParkName2());
            }
            if (StrUtil.isNotBlank(companyStd.getParkName3())) {
                companyStd.setPark3(parkAreaMap.get(companyStd.getParkName3()));
                companyStd.setLastPark(companyStd.getPark3());
                companyStd.setLastParkName(companyStd.getParkName3());
            }
            if (StrUtil.isNotBlank(companyStd.getParkName4())) {
                companyStd.setPark4(parkAreaMap.get(companyStd.getParkName4()));
                companyStd.setLastPark(companyStd.getPark4());
                companyStd.setLastParkName(companyStd.getParkName4());
            }
            if (StrUtil.isNotBlank(companyStd.getParkName5())) {
                companyStd.setPark5(parkAreaMap.get(companyStd.getParkName5()));
                companyStd.setLastPark(companyStd.getPark5());
                companyStd.setLastParkName(companyStd.getParkName5());
            }
            if (StrUtil.isNotBlank(companyStd.getParkName6())) {
                companyStd.setPark6(parkAreaMap.get(companyStd.getParkName6()));
                companyStd.setLastPark(companyStd.getPark6());
                companyStd.setLastParkName(companyStd.getParkName6());
            }
            System.out.println("   update company_std set park1 = " + companyStd.getPark1() + ",park2 = " + companyStd.getPark2() + ",park3 = " + companyStd.getPark3() + ",\n" +
                    "                               park4 = " + companyStd.getPark4() + ",park5 = " + companyStd.getPark5() + ",park6 = " + companyStd.getPark6() + ",\n" +
                    "                               park_name1 = '" + companyStd.getParkName1() + "',park_name2 = '" + companyStd.getParkName2() + "',park_name3 = '" + companyStd.getParkName3() + "',\n" +
                    "                               park_name4 = '" + companyStd.getParkName4() + "',park_name5 = '" + companyStd.getParkName5() + "',park_name6 = '" + companyStd.getParkName6() + "',\n" +
                    "                               last_park = " + companyStd.getLastPark() + ",last_park_name = '" + companyStd.getLastParkName() + "'\n" +
                    "        where reg_institute = '" + companyStd.getRegInstitute() + "';");
//            companyMapper.updateCompanyStd(companyStd);
        }

    }
}
